# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Pedro Lucas Porcellis <porcellis@eletrotupi.com>
pkgname=bupstash
pkgver=0.12.0
pkgrel=6
pkgdesc="Easy and efficient encrypted backups"
url="https://bupstash.io/"
# armhf,armv7,x86: sodium bindgen test fails
# s390x: fails to build nix crate
arch="all !armhf !armv7 !s390x !x86"
license="MIT"
makedepends="
	cargo
	cargo-auditable
	libsodium-dev
	lz4-dev
	sqlite-dev
	ronn
	zstd-dev
	"
options="net"
subpackages="$pkgname-doc"
source="$pkgname-$pkgver.tar.gz::https://github.com/andrewchambers/bupstash/archive/v$pkgver.tar.gz
	regex-features.patch
	unbundle-sqlite.patch
	libc-crate-update.patch
	"

_cargo_opts="--no-default-features --frozen"

prepare() {
	default_prepare

	# Rust target triple.
	local target=$(rustc -vV | sed -n 's/host: //p')

	# Build against system-provided lz4 and zstd.
	mkdir -p .cargo
	cat >> .cargo/config.toml <<-EOF
		[target.$target]
		lz4 = { rustc-link-lib = ["lz4"] }
		zstd = { rustc-link-lib = ["zstd"] }
	EOF

	cargo fetch --target="$CTARGET" --locked

	cd doc/man
	ronn -r *.md
}

build() {
	cargo auditable build $_cargo_opts --release
}

check() {
	cargo test $_cargo_opts
}

package() {
	install -Dm755 target/release/bupstash -t "$pkgdir"/usr/bin/
	for man in doc/man/*.?; do
		install -Dm644 "$man" \
			"$pkgdir"/usr/share/man/man${man##*.}/${man##*/}
	done
}

sha512sums="
a1fb8af217dcca4322bceb6286379096586c0b7359d7e794d8f8b2890dc2a3ee8cc8baace15b42a3466dedc83ed12443bb24931d817cb06702e62f5e46ff33f8  bupstash-0.12.0.tar.gz
c10c8dd9ddd17d53a730da07d2eb1595e9924ed4ec50aaf55db30e197f8cc77ca76194bfb4a04808db4be53789ba2eead3b0a23625e662911e38cb82ca730b34  regex-features.patch
9963dee4793d2c365ad05d0141dd7b28ddb4098d1b9b60561d6f3f05401dbdbb581b6a89e0d63ec0f5167a4e8478390eff6e3380581867d1dfe0ed2074449870  unbundle-sqlite.patch
781d2a8e8fb1776f40af20eecab0f64b1158fa1c989a0bc8e7df8b4f9a35ec8d925188f1d723b31495ed7aa228303b45b9c29320517041c3fba2e06d278ff029  libc-crate-update.patch
"
